package com.sbxBase.controller;

import com.common.entity.sbxBase.User;
import com.sbxBase.service.UserService;
import com.common.entity.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = "普通用户")
@RestController
@RequestMapping("/commonUser")
public class CommonUserController {

    @Resource
    private UserService userService;

    @GetMapping("{token}/logout")
    @ApiOperation("用户退出登录")
    public Result userLogout() {
        userService.userLogout();
        return Result.success();
    }


    @GetMapping("{token}/tokenByUserInfo")
    @ApiOperation("根据token获取用户信息")
    public Result tokenByUserInfo(@PathVariable @ApiParam("用户token") String token) {
        User user = userService.tokenByUserInfo(token);
        return Result.success(user);
    }

    @PutMapping
    @ApiOperation("用户信息修改")
    public Result update(@ApiParam("昵称") @RequestParam(value = "nickName",required = false) String nickName,
                         @ApiParam("头像") @RequestParam(value = "head",required = false) String head,
                         @ApiParam("密码") @RequestParam(value = "password",required = false) String password,
                         @ApiParam("手机号") @RequestParam(value = "phone",required = false) String phone,
                         @ApiParam("邮箱") @RequestParam(value = "email",required = false) String email) {
        userService.update(nickName,head,password,phone,email);
        return Result.success();
    }



}
